#include "BellSprite.h"
#include "CardSprite.h"
#include "ShelfSprite.h"
#include "ComboProgress.h"
#include "PlayLayer.h"
#include "AudioManage.h"

static const char* CONST_PNG_BELL = "Bell/bell.png";
static const char* CONST_PNG_BELL_BUTTON_N = "Bell/bell_button2.png";
static const char* CONST_PNG_BELL_BUTTON_S = "Bell/bell_button_S.png";

static bool bellEnable = true;

BellSprite::BellSprite(int* keysP)
{
	this->keys = keysP;

	this->create();
	this->initWithFile(CONST_PNG_BELL);	

	this->bellButton = MenuItemImage::create(CONST_PNG_BELL_BUTTON_N, CONST_PNG_BELL_BUTTON_S,
		CC_CALLBACK_0(BellSprite::bellButtonCallBack, this));

	float bell_width = this->getContentSize().width;
	float bell_height = this->getContentSize().height;

	//bellButton->setPosition(bell_width / 2, bell_height * 0.83f);
	bellButton->setPosition(bell_width / 2, bell_height / 2);
	Menu* bellMenu = Menu::create(bellButton, NULL);
	bellMenu->setPosition(Vec2::ZERO);

	this->addChild(bellMenu);
}


BellSprite::~BellSprite()
{
}

void BellSprite::bellButtonCallBack(Ref* sender)
{
	if (!bellEnable)
	{
		return;
	}

	BellSprite* bSprite = (BellSprite*)sender;
	bool result = CardSprite::checkKeys(bSprite->keys);

    AudioManage::bellSound();

	if (result)
	{
        AudioManage::rightSound();
		bellEnable = false;
        PlayLayer::addScore();
        ComboProgress::addProgress();
		CardSprite::nextCard();
        ShelfSprite::keysRight();
	}
	else
	{
		AudioManage::wrongSound();
		PlayLayer::subScore();
		ShelfSprite::keysWrong();
		ComboProgress::newProgress();
	}
}

void BellSprite::enableBell()
{
	bellEnable = true;
}
